package com.jse.keyword.zfinal;

import java.util.Arrays;

import org.junit.Test;


public class FinalStringTest {
	private static String as ="a";
	private static String bs ="b";
	
	private final char value[];
	
	public FinalStringTest() {
		this.value = new char[0];
	}
	
	@Test
	public void testGlobalFinal() {
		char[] names = {'a', 'b', 'c'};
		//final关键字修饰之后，引用不能变，因为在编译时期
//		this.value = Arrays.copyOf(names, names.length);
		value[0] = 'a';
	}
	
	/**
	 * 字符串创建对象
	 * 
	 * final解惑，参考http://stackoverflow.com/questions/19418427/comparing-strings-with-which-are-declared-final-in-java/19418517#19418517
	 */
	@Test
	public void testEquals() {
		String s1="ab";
		String s2="c";
		//变量创建对象在运时候创建，参考jsl 3.10.5 String Literals
		String s3 = s1+s2;
		
		String s4="abc";
		
		//final类型的字符串常量是不可变的，在编译时就赋值了
		final String ss1="ab";
		final String ss2="cd";
		String ss = ss1+ss2;
		System.out.println("ss1+ss2 : " + (ss1+ss2));//abc
		System.out.println("s3==s4 : " + (s3==s4));//false
		//如果s3.intern()==s4.intern()不加()，打印出来的结果只有false，查看+操作符 TODO
		System.out.println("s3.intern()==s4.intern() : " + (s3.intern()==s4.intern()));//当s3.equals(s4)为true时，此表达式才返回true
		System.out.println("(ss1+ss2) ==\"abcd\" : " + ((ss1+ss2) =="abcd"));//true，参考4.12.4. final Variables，
		System.out.println("ss==\"abcd\" : " + (ss=="abcd"));
		//静态变量为什么不会为
		System.out.println("(as+bs)==s1 ：" + ((as+bs)==s1));//输出false
		
		
		int i = 1;
		int j = 1;
		String sum = "s" + i + j;
		System.out.println(sum);
	}
}
